// Copyright 2022 jeff.li. and/or its affiliates.

#pragma once

#include <tbir/runtime/container/opaque_object.h>
#include <tbir/runtime/object.h>

namespace tbir::runtime {

    struct OpaqueObjectNode : public Object {
        void *ptr = nullptr;           // instance ptr
        int64_t tag = 0;               // for type check
        FOpaqueObjectDeleter deleter;  // for free ptr
        static constexpr int BUFFER_SIZE = 256;
        unsigned char buffer[BUFFER_SIZE];

        ~OpaqueObjectNode() {
            if (deleter && ptr) {
                (*deleter)(ptr);
            }
        }

        static constexpr const uint32_t _type_index = TypeIndex::kRuntimeOpaqueObject;
        static constexpr const char *_type_key = "runtime.OpaqueObject";
        TBIR_DECLARE_FINAL_OBJECT_INFO(OpaqueObjectNode, Object);
    };

}  // namespace tbir::runtime
